package com.xdxc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xdxc.model.entity.UserAnswer;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    @Update("<script>" +
            "INSERT INTO user_answer " +
            "(id, paper_id, qu_id, answer_type, answer_ids, answer_text, answer_files, version, is_deleted, update_time, answer_type_text, user_id) " +
            "VALUES " +
            "<foreach collection='list' item='entity' separator=','>" +
            "(" +
            "#{entity.id}, " +
            "#{entity.paperId}, " +
            "#{entity.quId}, " +
            "#{entity.answerType}, " +
            "#{entity.answerIds, typeHandler=com.xdxc.utils.JsonTypeHandler}, " +
            "#{entity.answerText}, " +
            "#{entity.answerFiles, typeHandler=com.xdxc.utils.JsonTypeHandler}, " +
            "#{entity.version}, " +
            "#{entity.isDeleted}, " +
            "#{entity.updateTime}, " +
            "#{entity.answerTypeText}, " +
            "#{entity.userId}" +
            ")" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE " +
            "answer_ids = VALUES(answer_ids), " +
            "answer_text = VALUES(answer_text), " +
            "answer_files = VALUES(answer_files), " +
            "version = VALUES(version), " +
            "is_deleted = VALUES(is_deleted), " +
            "update_time = NOW(), " +
            "answer_type_text = VALUES(answer_type_text), " +
            "user_id = VALUES(user_id)" +
            "</script>")
    void batchUpsert(@Param("list") List<UserAnswer> entities);
}